package com.bonc.rms.dao.impl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.bonc.rms.dao.LoginDao;
import com.bonc.rms.utils.IESSearchUtil;
import com.bonc.rms.utils.impl.ESSearchUtilImpl;

@Repository(value = "loginDaoImpl")
public class LoginDaoImpl implements LoginDao {

	@Override
	public List<Map<String, Object>> getResume() {
		IESSearchUtil iesSearchUtil = new ESSearchUtilImpl();
		List<Map<String, Object>> resumeList = iesSearchUtil.getPageListByKeyword("company", "公司", 10, 0);
		return resumeList;
	}

	@Override
	public Map<String, Double> getByTerm(String item) {
		Map<String, Double> dashBordDataMap = new HashMap<>();
		IESSearchUtil iesSearchUtil = new ESSearchUtilImpl();
		Map<String, Double> resultMap = iesSearchUtil.termAgg(item).get(0);
		Iterator<String> iterator = resultMap.keySet().iterator();
		while (iterator.hasNext()) {
			String str = iterator.next();
			dashBordDataMap.put(str, resultMap.get(str) == null ? 0.0 : resultMap.get(str));
		}
		return dashBordDataMap;
	}

	@Override
	public Map<String, Long> getByRange(String item) {
		Map<String, Long> dashBordDataMap = new HashMap<>();
		IESSearchUtil iesSearchUtil = new ESSearchUtilImpl();
		Map<String, Long> resultMap;
		if (item.equals("age")) {
			resultMap = iesSearchUtil.rangeAgg("age", 25, 35);
		} else {
			resultMap = iesSearchUtil.rangeAgg("workingExperience", 3, 7);
		}
		Iterator<String> iterator = resultMap.keySet().iterator();
		while (iterator.hasNext()) {
			String str = iterator.next();
			dashBordDataMap.put(str, resultMap.get(str) == null ? 0 : resultMap.get(str));
		}
		return dashBordDataMap;
	}

}
